// 导入axios
import axios from 'axios'

import store from '@/store'

// 克隆一份axios
const request = axios.create({
  baseURL: 'http://interview-api-t.itheima.net',
  timeout: 5000
})

// 添加请求拦截器
request.interceptors.request.use((config) => {
  // 添加请求头
  // config.headers.Authorization = token值
  config.headers.Authorization = 'Bearer ' + store.state.user.token
  return config
}
, (error) => Promise.reject(error)
)

// 添加响应拦截器
request.interceptors.response.use((response) => response.data
  , (error) => Promise.reject(error))

// 导出配置好的request
export default request
